-
Notifications
You must be signed in to change notification settings - Fork 7.6k
video: gc2145: addition of CSI output support #89571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
video: gc2145: addition of CSI output support #89571
Conversation
4c5ccf6
to
c561479
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the patch soup snippets to test with UVC:
git remote add tvai https://github.com/tinyvision-ai-inc/zephyr
git fetch tvai
git cherry-pick tvai/pr-usb-uvc~9..tvai/pr-usb-uvc
west build -b arduino_nicla_vision/stm32h747xx/m7 samples/subsys/usb/uvc/
west flash
This still works!
#define VIDEO_MIPI_CSI2_DT_YUV422_8 0x1e | ||
#define VIDEO_MIPI_CSI2_DT_YUV422_10 0x1f | ||
#define VIDEO_MIPI_CSI2_DT_RGB444 0x20 | ||
#define VIDEO_MIPI_CSI2_DT_RGB555 0x21 | ||
#define VIDEO_MIPI_CSI2_DT_RGB565 0x22 | ||
#define VIDEO_MIPI_CSI2_DT_RGB666 0x23 | ||
#define VIDEO_MIPI_CSI2_DT_RGB888 0x24 | ||
#define VIDEO_MIPI_CSI2_DT_RAW6 0x28 | ||
#define VIDEO_MIPI_CSI2_DT_RAW7 0x29 | ||
#define VIDEO_MIPI_CSI2_DT_RAW8 0x2a | ||
#define VIDEO_MIPI_CSI2_DT_RAW10 0x2b | ||
#define VIDEO_MIPI_CSI2_DT_RAW12 0x2c | ||
#define VIDEO_MIPI_CSI2_DT_RAW14 0x2d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to mostly match the naming of include/media/mipi-csi2.h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggesting a change for the small syntax bugfix remote-endpoint
-> remote-endpoint-label
if that is ok to ask.
Otherwise I can open a separate PR as it is not a bug introduced by this and CI does not fail due to this.
[EDIT: It does but https://github.com//pull/89627 is where the fix is]
c561479
to
b016299
Compare
Corrected the PIXEL_RATE part that I got wrong within the sensor side when doing the ST_MIPID02 driver at the same time. |
b016299
to
20cb045
Compare
Small update to avoid if (err) style error checking and instead use MISRA validated if (err < 0). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If interested in improving this now, using DT_INST_ENDPOINT_BY_ID(inst, pid, eid)
can be nicer, but I do not see this as blocking at least IMHO.
Thank you for extending this sensorr!
/* MIPI-CSI registers - on page 3 */ | ||
#define GC2145_REG_DPHY_MODE1 0x01 | ||
#define GC2145_DPHY_MODE1_CLK_EN BIT(0) | ||
#define GC2145_DPHY_MODE1_LANE0_EN BIT(1) | ||
#define GC2145_DPHY_MODE1_LANE1_EN BIT(2) | ||
#define GC2145_DPHY_MODE1_CLK_LANE_P2S_SEL BIT(7) | ||
|
||
#define GC2145_REG_DPHY_MODE2 0x02 | ||
#define GC2145_DPHY_MODE2_CLK_DIFF(a) ((a) & 0x07) | ||
#define GC2145_DPHY_MODE2_LANE0_DIFF(a) (((a) & 0x07) << 4) | ||
|
||
#define GC2145_REG_DPHY_MODE3 0x03 | ||
#define GC2145_DPHY_MODE3_LANE1_DIFF(a) ((a) & 0x07) | ||
#define GC2145_DPHY_MODE3_CLK_DELAY BIT(4) | ||
#define GC2145_DPHY_MODE3_LANE0_DELAY BIT(5) | ||
#define GC2145_DPHY_MODE3_LANE1_DELAY BIT(6) | ||
|
||
#define GC2145_REG_FIFO_FULL_LVL_LOW 0x04 | ||
#define GC2145_REG_FIFO_FULL_LVL_HIGH 0x05 | ||
#define GC2145_REG_FIFO_MODE 0x06 | ||
#define GC2145_FIFO_MODE_READ_GATE BIT(3) | ||
#define GC2145_FIFO_MODE_MIPI_CLK_MODULE BIT(7) | ||
|
||
#define GC2145_REG_BUF_CSI2_MODE 0x10 | ||
#define GC2145_CSI2_MODE_DOUBLE BIT(0) | ||
#define GC2145_CSI2_MODE_RAW8 BIT(2) | ||
#define GC2145_CSI2_MODE_MIPI_EN BIT(4) | ||
#define GC2145_CSI2_MODE_EN BIT(7) | ||
|
||
#define GC2145_REG_MIPI_DT 0x11 | ||
#define GC2145_REG_LWC_LOW 0x12 | ||
#define GC2145_REG_LWC_HIGH 0x13 | ||
#define GC2145_REG_DPHY_MODE 0x15 | ||
#define GC2145_DPHY_MODE_TRIGGER_PROG BIT(4) | ||
|
||
#define GC2145_REG_FIFO_GATE_MODE 0x17 | ||
#define GC2145_REG_T_LPX 0x21 | ||
#define GC2145_REG_T_CLK_HS_PREPARE 0x22 | ||
#define GC2145_REG_T_CLK_ZERO 0x23 | ||
#define GC2145_REG_T_CLK_PRE 0x24 | ||
#define GC2145_REG_T_CLK_POST 0x25 | ||
#define GC2145_REG_T_CLK_TRAIL 0x26 | ||
#define GC2145_REG_T_HS_EXIT 0x27 | ||
#define GC2145_REG_T_WAKEUP 0x28 | ||
#define GC2145_REG_T_HS_PREPARE 0x29 | ||
#define GC2145_REG_T_HS_ZERO 0x2a | ||
#define GC2145_REG_T_HS_TRAIL 0x2b | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will try to port it to the CCI library, I got started for DVP and will do it after the merge
drivers/video/gc2145.c
Outdated
.bus_type = DT_PROP_OR(DT_CHILD(DT_INST_CHILD(0, port), endpoint), bus_type, | ||
VIDEO_BUS_TYPE_PARALLEL), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be possible to use the macro DT_INST_ENDPOINT_BY_ID(inst, pid, eid) for walking down the port and endpoint
:
zephyr/include/zephyr/devicetree/port-endpoint.h
Lines 105 to 163 in c35bb0d
/** | |
* @brief Get an endpoint node from its id and its parent port id | |
* | |
* Given a device instance number, a port ID and an endpoint ID, return the endpoint node. | |
* It handles various ways of how a port and an endpoint could be defined as described in | |
* @ref DT_INST_PORT_BY_ID and below. | |
* | |
* Example usage with DT_INST_ENDPOINT_BY_ID() to get the @c endpoint or @c endpoint@0 node: | |
* | |
* @code{.c} | |
* DT_INST_ENDPOINT_BY_ID(inst, 0, 0) | |
* @endcode | |
* | |
* Example devicetree fragment: | |
* | |
* @code{.dts} | |
* &device { | |
* port { | |
* endpoint { | |
* }; | |
* }; | |
* }; | |
* @endcode | |
* | |
* @code{.dts} | |
* &device { | |
* port { | |
* #address-cells = <1>; | |
* #size-cells = <0>; | |
* endpoint@0 { | |
* reg = <0x0>; | |
* }; | |
* }; | |
* }; | |
* @endcode | |
* | |
* @code{.dts} | |
* &device { | |
* ports { | |
* #address-cells = <1>; | |
* #size-cells = <0>; | |
* port@0 { | |
* reg = <0x0>; | |
* #address-cells = <1>; | |
* #size-cells = <0>; | |
* endpoint@0 { | |
* reg = <0x0>; | |
* }; | |
* }; | |
* }; | |
* }; | |
* @endcode | |
* | |
* @param inst instance number | |
* @param pid port ID | |
* @param eid endpoint ID | |
* @return endpoint node associated with @p eid and @p pid | |
*/ | |
#define DT_INST_ENDPOINT_BY_ID(inst, pid, eid) \ |
20cb045
to
123e2dc
Compare
I fixed the macro to get the bus-type. Should have done that already in the first place. Thanks for noticing. |
Apparently some tests are not successful but I have to say that I do not understand what is failing. |
Maybe the CI issues will get resolved once https://github.com/zephyrproject-rtos/zephyr/pull/89571/files#r2080630046 is resolved (fix: merge #89627 ?)
|
oh yeah indeed. That #89627 should now be ready I think so we should be able to merge it before this one. Or maybe adding in the description that this PR depends on the other one might help the CI build ? |
You might need to rebase this PR on top of #89627's commits. Alas Github is not able to grok the order in which it should apply patches like maintainers would in a mailing list. |
Will be rebased on top of #89764 since this is the PR which now expose the VIDEO_CID_LINK_FREQUENCY control and the MIPI_CSI2 data type macros. |
#define VIDEO_MIPI_CSI2_DT_RAW10 0x2b | ||
#define VIDEO_MIPI_CSI2_DT_RAW12 0x2c | ||
#define VIDEO_MIPI_CSI2_DT_RAW14 0x2d | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to define all the CSI2 data types now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright yes !! Just converting to draft for the moment in order to avoid polluting the PR listing, while updating this.
123e2dc
to
8425649
Compare
The MIPI data type macros are removed since I moved them into ST_MIPID02 PR which is a dependency for this PR since it also introduce the LINK_FREQUENCY ctrl. Last push allows you to see the latest modification (introduction of LINK_FREQUENCY). Then I will rebase this PR once ST_MIPID02 serie get agreed and CCI PR get merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to review it again when dependencies get merged, but LGTM in the meantime.
One minor issue observed... that is probably me chasing ghosts rather than finding bugs!
@@ -1082,6 +1236,14 @@ static int gc2145_set_fmt(const struct device *dev, enum video_endpoint_id ep, | |||
return ret; | |||
} | |||
|
|||
if (cfg->bus_type == VIDEO_BUS_TYPE_CSI2_DPHY) { | |||
ret = gc2145_config_csi(dev, fmt->pixelformat, fmt->width, fmt->height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the format is not supported for CSI but it is for DVP (like 320x240), then drv_data->fmt = *fmt
would still be applied, but the format would not be valid. Probably not a big issue though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the drv_data->fmt setting after CSI check.
511449f
to
1946a51
Compare
Simply rebased on HEAD. |
Add standard data-type macros within the video.h in order to avoid having to redefine them all in each and every CSI based driver. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
1946a51
to
cc52cc4
Compare
Fixed @josuah comment and added 3 commits from PR ST_MIPID02 in order to be able to properly build the driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** Menu integer type, standard or driver-defined menu */ | ||
VIDEO_CTRL_TYPE_INTEGER_MENU = 6, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[typo]
The commit message still has MENU_INTEGER
in it.
Add a new INTEGER_MENU type allowing to store signed 64bits integer into a menu. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add a ctrl VIDEO_CID_LINK_FREQ to indicate to a sink the frequency at which a device streams data over CSI2. Since not all source device currently provide the LINK_FREQ control, add a helper function to retrieve it, with a fall-back by doing an approximate via the PIXEL_RATE control. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Do not enable by default the DVP streaming to avoid conflict with the introduction of the MIPI mode of the GC2145. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Add possibility to use the gc2145 sensor in CSI mode by adding the bus-type property in the device-tree. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Since QVGA resolution is currently not working in CSI, use VGA as default resolution to avoid failing during the init of the driver. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
cc52cc4
to
c509b92
Compare
Following a comment in PR 89764 which contains the I update this PR to also have the same valid commits. Now that LINK_FREQ ctrl is no more READ_ONLY by default, add setting the READ_ONLY flag within the driver here since with this driver the LINK_FREQ ctrl is readl-only. |
|
The PR adds GC2145 driver support to allow controlling a CSI based GC2145 sensor.
This is the setup used on the STM32MP13-DK board in which case the GC2145 is connected to the ST-MIPID02 CSI bridge (PR to be pushed as well) into the DCMIPP (ongoing PR 89407 with added parallel support to be pushed).
The current driver currently support 320x240 / 640x480 and 1600x1200 resolution, however for the time being I haven't been able to make the 320x240 resolution work in CSI (probably a PIXELRATE issue with the CSI receiver timing to be adjusted ...) so I only allow 640x480 and 1600x1200 resolution in CSI for the moment.
I've also added standard CSI2 DT macros into video.h so that not all sensor or receiver will have to define them.
I do not have a setup with a DVP GC2145 so could someone run a sanity test with those patches in a DVP mode.